package com.hsj.goldstore.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.hsj.goldstore.R;
import com.hsj.goldstore.bean.GoodsBean;
import com.hsj.goldstore.bean.LoginBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/3/26.
 */

public class GoodsAdapter extends RecyclerView.Adapter<GoodsAdapter.GoodsViewHolder> {
    private List<GoodsBean> list = new ArrayList<>();
    private Context context;
    private MyItemClick onItemClick;

    public GoodsAdapter(Context context, List<GoodsBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public GoodsViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        GoodsViewHolder holder = new GoodsViewHolder(LayoutInflater.from(context)
                .inflate(R.layout.item_goods, parent, false));

        return holder;
    }

    @Override
    public void onBindViewHolder(GoodsViewHolder holder, final int position) {
        holder.ivPic.setImageResource(R.mipmap.ic_zb_3);

        holder.ivHeart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onItemClick.headClick(position);
            }
        });

    }

    @Override
    public int getItemCount() {
        return list.size() + 10;
    }

    class GoodsViewHolder extends RecyclerView.ViewHolder {
        TextView tvName, tvPrice, tvPriceAndScord;
        ImageView ivPic, ivHeart;

        public GoodsViewHolder(View itemView) {
            super(itemView);
            tvName = itemView.findViewById(R.id.tv_name);
            tvPrice = itemView.findViewById(R.id.tv_price);
            tvPriceAndScord = itemView.findViewById(R.id.tv_price_and_scold);
            ivPic = itemView.findViewById(R.id.iv_pic);
            ivHeart = itemView.findViewById(R.id.iv_heard);
        }
    }

    /**
     *
     * @param onItemClick 点击事件监听
     */
    public void onMyItemClick(MyItemClick onItemClick) {
        this.onItemClick = onItemClick;
    }
    /**
     * 点击事件监听
     */
    public interface MyItemClick {
        /**
         *
         * @param position 点赞功能
         */
        void headClick(int position);
}

}
